package com.appspot.zarm.gomoku.transfer;

import com.appspot.zarm.gomoku.Coord;
import com.appspot.zarm.transfer.GamesListExternalizer;
import com.appspot.zarm.transfer.JsonTransferer;
import com.google.gson.Gson;

public class GomokuJsonTransferer extends JsonTransferer {

	@Override
	public String transfer(Object object) {
		if ( object instanceof GamesListExternalizer ) {
			return super.transfer(object);
		} else if (object instanceof GameExternalizer) {
			GameExternalizer gameExternalizer = (GameExternalizer) object;
			return new Gson().toJson(gameExternalizer.getGameState());
		}
		return null;
	}
	
	@Override
	public Object transfer(String rawData) {
		Coord position = (Coord)new Gson().fromJson(rawData, CoordImpl.class);
		return position;
	}
}
